package com.example.rabbitdemo.controller;


import com.example.rabbitdemo.config.RabbitmqConfig;
import com.example.rabbitdemo.services.RabbitMqSenderService;
import groovy.util.logging.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class demoController {
    @Resource
    private RabbitMqSenderService senderService;

    @GetMapping("/test1")
    public String test1(String data){
        Message message=new Message(data.getBytes());
        senderService.send(RabbitmqConfig.DIRECT_EXCHANGE,"demo",message);
        return "ok";
    }

    @GetMapping("/test2")
    public String test2(String data){
        Message message=new Message(data.getBytes());
        senderService.sendQueue(RabbitmqConfig.DIRECT_EXCHANGE,"demo2",message);
        return "ok";
    }


    @GetMapping("/topic")
    public String topicOne(String data,String routingKey){
        Message message=new Message(data.getBytes());
        senderService.sendQueue(RabbitmqConfig.TOPIC_EXCHANGE,routingKey,message);
        return "ok";
    }

    @GetMapping("/fanout")
    public String fanoutOne(String data){
        Message message=new Message(data.getBytes());
        senderService.sendQueue(RabbitmqConfig.FANOUT_EXCHANGE,"",message);
        return "ok";
    }




}
